<template>
  <l-layout class="l-tab-page">
    <div id="designer"></div>
  </l-layout>
</template>

<script>
//var Report; //Designer
export default {
  components: {},
  data() {
    return {};
  },
  mounted() {
    //报表文档
    //https://www.stimulsoft.com/en/documentation/online/programming-manual/index.html?reports_js_web_designer_save_report.htm
    //https://blog.csdn.net/qq_44408913/article/details/121972665
    window.Stimulsoft.Base.StiLicense.loadFromFile("/cdn/stimulsoft/license.key");
    window.Stimulsoft.Base.Localization.StiLocalization.setLocalizationFile("/cdn/stimulsoft/zh-CHS.xml");
  },
  computed: {},
  methods: {
    //创建报表
    init(data, row) {
      var _this = this;
      var options = new window.Stimulsoft.Designer.StiDesignerOptions();
      options.appearance.fullScreenMode = false;
      var designer = new window.Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
      var report = new window.Stimulsoft.Report.StiReport();
      report.loadFile("/cdn/stimulsoft/Report.mrt"); //SimpleList.mrt
      designer.report = report;

      var dataSet = new window.Stimulsoft.System.Data.DataSet("customJSON");
      dataSet.readJson(data);
      //report.dictionary.databases.clear();
      report.regData("customJSON", "customJSON", dataSet);

      designer.renderHtml("designer");
      //Designer=designer;
      //Report = report;

      designer.onSaveReport = function (e) {
        var jsonStr = e.report.saveToJsonString();
        //console.log(jsonStr);
        _this.$emit("repostSave", { jsonStr: jsonStr, reportid: row.f_Id });
      };
    },

    //编辑报表
    setForm(data, row, url) {
      //console.log("设置表单：");
      var _this = this;
      var options = new window.Stimulsoft.Designer.StiDesignerOptions();
      options.appearance.fullScreenMode = false;
      var designer = new window.Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
      var report = new window.Stimulsoft.Report.StiReport();

      report.loadFile(url || "/cdn/stimulsoft/Report.mrt");
      designer.report = report;
      var dataSet = new window.Stimulsoft.System.Data.DataSet("customJSON");
      dataSet.readJson(data);
      report.regData("customJSON", "customJSON", dataSet);
      designer.renderHtml("designer");
      //Designer=designer;
      //Report = report;

      designer.onSaveReport = function (e) {
        var jsonStr = e.report.saveToJsonString();
        //console.log(jsonStr);
        _this.$emit("repostSave", { jsonStr: jsonStr, reportid: row.f_Id });
      };
    },

    //预览报表
    viewForm(data, row, url) {
      var options = new window.Stimulsoft.Viewer.StiViewerOptions();
      var viewer = new window.Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
      var report = new window.Stimulsoft.Report.StiReport();
      report.loadFile(url || "/cdn/stimulsoft/Report.mrt");
      viewer.report = report;

      var dataSet = new window.Stimulsoft.System.Data.DataSet("customJSON");
      dataSet.readJson(data);
      report.regData("customJSON", "customJSON", dataSet);

      viewer.renderHtml("designer");
      //Designer=viewer;
      //Report = report;
    },
  },
};
</script>
